<template>
  <div class="bar">
    <a-row type="flex">
      <a-col :span="20">
        <a-row type="flex" :gutter="[8, 8]">
          <a-col>
            <div class="itemWrap">
              <div class="label">
                <span>型号</span>
              </div>
              <div class="separator">
                <span>:</span>
              </div>
              <div class="content">
                <a-input class="search-input" v-model="search.type" allow-clear />
              </div>
            </div>
          </a-col>
          <a-col>
            <div class="itemWrap">
              <div class="label">
                <span>时间选择</span>
              </div>
              <div class="separator">
                <span>:</span>
              </div>
              <div class="content">
                <a-range-picker v-model="rangeTime" @change="onTimeChange"/>
              </div>
            </div>
          </a-col>
          <a-col>
            <div class="itemWrap">
              <div class="label">
                <span>类型选择</span>
              </div>
              <div class="separator">
                <span>:</span>
              </div>
              <div class="content">
                <a-select class="search-input" v-model="search.classType" placeholder="请选择">
                  <a-select-option
                    v-for="(dataItem,index) in selectTypeList"
                    :key="index"
                    :value="dataItem.name"
                  >{{ dataItem.name }}</a-select-option>
                </a-select>
              </div>
            </div>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="4" style="text-align: right;">
        <a-button type="primary" style="margin-right: 8px;" @click="searchData()">搜索</a-button>
        <a-button type="primary" @click="restSearchData()">重置</a-button>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import { getRoleId } from "@/unit/tool";
import { WarrantyType } from "@/unit/constantValue";
import moment from "moment";

export default {
  name: "ServiceStatistics",
  components: {},
  props: {
    initData: Object
  },
  data() {
    return {
      userName: "",
      name: "",
      role: "",
      compId: "",
      expand: false,
      rangeTime: [],
      statusLists: [],
      selectTypeList: [
        { name: "数控系统" },
        { name: "i/o" },
        { name: "伺服驱动" },
        { name: "电机" },
        { name: "全部" }
      ],
      warrantyStatusLists: WarrantyType,
      search: {
        beginTime: "",
        endTime: "",
        modulType: "",
        ioUnitType: "",
        ioUnitId: "",
        servoModel: "",
        servoId: "",
        servoProductTime: "",
        elecModel: "",
        type: "",
        elecId: ""
      }
    };
  },
  watch: {
    initData: {
      handler(val) {
        let { rangeTime, ...rest } = val;
        this.search = { rangeTime, ...rest };
        this.rangeTime = rangeTime;
        this.search.type = val.type;
        // this.disabledDate(val.endTime)
      },
      immediate: true
    }
  },
  methods: {
    onTimeChange(e) {
      let [beginTime, endTime] = e;
      if (e.length > 0) {
        this.search.beginTime = `${moment(beginTime).format(
          "YYYY-MM-DD"
        )} 00:00:00`;
        this.search.endTime = `${moment(endTime).format(
          "YYYY-MM-DD"
        )} 23:59:59`;
      } else {
        this.search.beginTime = "";
        this.search.endTime = "";
      }
    },
    handlePanelChange2(e) {
      this.rangeTime = e;
      this.search.beginTime = `${moment(e[0]).format("YYYY-MM")}`;
      this.search.endTime = `${moment(e[1]).format("YYYY-MM")}`;
    },
    checkBoxChange(e) {
      if (e.target.checked) {
        this.search.partCheckFlag = 0;
      } else {
        this.search.partCheckFlag = 1;
      }
    },
    searchData() {
      this.$emit("emitSearchData", {
        ...this.search,
        rangeTime: this.rangeTime
      });
    },
    restSearchData() {
      let { rangeTime, ...rest } = this.initData;
      this.search = { ...rest };
      this.search.classType = '全部'
      // this.rangeTime = rangeTime;
      this.$emit("emitSearchData", {
        ...this.search,
        // rangeTime: this.rangeTime
      });
    }
  },
  created() {},
  mounted() {
    getRoleId(this);
  },
  computed: {}
};
</script>

<style scoped="scoped">
.bar {
  width: 100%;
  background-color: #ffffff;
  border: 1px solid #e8e8e8;
  padding: 16px 16px 16px 16px;
}

.itemWrap {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

.itemWrap > .label {
  min-width: 90px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #646464;
  text-align: right;
}

.itemWrap > .separator {
  padding: 0px 4px;
}

.itemWrap > .content {
  width: 100%;
  padding: 0px 1px;
}
.search-input {
  width: 120px;
}
</style>
